﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NLLSite.Administrator
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            bool block = false;
            DAL_Class.Admin admincs = new DAL_Class.Admin();
            IEnumerable<DAL_Class.Administrator> iad = admincs.login(some1.Value, GetMD5Hash(some3.Value));
            if (iad.Count() > 0)
            {

                foreach (DAL_Class.Administrator ad in iad)
                {
                    Session["objadmin"] = ad;
                    Session["role"] = ad.Role;
                    block = ad.Status;
                    
                }
                if (block)
                    Response.Redirect("Default.aspx");
                else
                    Label1.Text = "Tài khoản đã bị khóa.";

            }
            else {
                Label1.Text = "Đăng nhập không thành công.";
            }
           // Session["Role"] = "Admin";
            
        }
        public static string GetMD5Hash(string input)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();
            return password;
        }
    }
}